import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import ArticleList from '@/components/ArticleList'
import ArticleAdd from '@/components/ArticleAdd'
import MyRichEditor from '@/components/myblog/MyRichEditor'
import MyCodeTxt from '@/components/MyCodeTxt'
import ManageBlog from '@/components/myblog/ManageBlog'
import ManageType from '@/components/myblog/ManageType'
import MyBlogDetail from '@/components/myblog/MyBlogDetail'
import Login from '@/components/login/Login'
import MyBlogListHome from '@/components/myblog/MyBlogListHome'
import MyBlogList from '@/components/myblog/MyBlogList'
import MyBlogDetailShow from '@/components/myblog/MyBlogDetailShow'
import Person from '@/components/person/Person'
import PersonDetail from '@/components/person/PersonDetail'
/**
 * 重写路由的push方法
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

Vue.use(Router)

const routes = [
  {
    path:"/person",
    component:Person,
    children:[
      {path:"/personDetail",component:PersonDetail},
   ]
  },
  {
    path:"/home",
    name:"home",
    component:Home,
    children:[
       {path:"/articleList/:articleTypeName",component:ArticleList},
       {path:"/myCodeTxt",component:MyCodeTxt},
    ]
  },
  {
    path:"/myBlogListHome",
    component:MyBlogListHome,
    children:[
      {path:"/myBlogList",component:MyBlogList},
      {path:"/myBlogDetailShow/:blogId",component:MyBlogDetailShow},
    ]
  },
  {
    path:"/articleAdd",
    component:ArticleAdd,
    children:[
      {path:"/myRichEditor",component:MyRichEditor},
      {path:"/manageBlog",component:ManageBlog},
      {path:"/manageType",component:ManageType},
      {path:"/myBlogDetail/:myBlogId",component:MyBlogDetail},
    ]
  },
  {path:"/login",component:Login},
  {path:"*",redirect:'/myCodeTxt'}
]

const router = new Router({
  mode:'history',  //hash模式改为history模式
  routes
})


export default router;